import cv2
import matplotlib.pyplot as plt
img = cv2.imread("../images/flower.png")
img_gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
plt.hist(img_gray.flatten(),bins=255,density=True)
ret,img_binary = cv2.threshold(img_gray,200,255,cv2.THRESH_OTSU)
print(f"设置的thresh 是 255  OTSU算法设置的thresh {ret}")
cv2.imshow(" binary image ",img_binary)
cv2.waitKey(0)